﻿namespace TVersityDotNet.MediaLib
{
    using System;
    using System.Runtime.Serialization;
    using System.Xml.Linq;

    [DataContractAttribute]
    public class MediaLibPhoto : MediaLibMediaItem
    {
        [DataMember]
        public string Album { get; set; }
        [DataMember]
        public string Resolution { get; set; }
        [DataMember]
        public DateTime Date { get; set; }
        [DataMember]
        public bool Restricted { get; set; }

        public MediaLibPhoto(XElement xmlElement)
        {
            this.SearchClass = MediaLibClassType.Photo;
            this.RawXml = xmlElement;
            this.ProcessXmlElement();
        }

        public new void ProcessXmlElement()
        {
            base.ProcessXmlElement();
            this.Resolution = this.ResElement.Attribute("resolution").Value;
            this.Restricted = bool.Parse(this.RawXml.Attribute("restricted").Value);
            this.Date = this.parseDT(this.RawXml.Element(XName.Get("date", MediaLibResponseItem.Namespace_DC)).Value);
            this.Album = this.RawXml.Element(XName.Get("album", MediaLibResponseItem.Namespace_Upnp)).Value;
        }

        private DateTime parseDT(string dt)
        {
            return DateTime.Parse(dt.Replace("T", " "));
        }
    }
}
